﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Batman.Maintenance
{
    public class MaintenanceAdmin
    {
        private static List<IMaintenanceModel> Models;

        static MaintenanceAdmin()
        {
            Models = new List<IMaintenanceModel>();
        }

        public static List<IMaintenanceModel> Get()
        {
            return Models;
        }

        /// <summary>
        /// 查询id数据模型
        /// </summary>
        /// <param name="modelId"></param>
        /// <returns></returns>
        public static IMaintenanceModel Get(string modelId) => Models.FirstOrDefault(t => t.Id == modelId);

        /// <summary>
        /// 注册
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static void Registe<T>() where T : class, IMaintenanceModel, new()
        {
            var type = typeof(T);
            var instance = Activator.CreateInstance<T>();
            Models.Add(instance);
        }
    }
}
